#!/bin/bash
rootdir=`pwd|tr -d '\n'`

pydir=$rootdir/src/python
dataroot=$rootdir/data
iaskroot=$dataroot/iask
iaskxmldir=$iaskroot/xml
iaskpagedir=$iaskroot/page

mkdir -p $dataroot
mkdir -p $rootdir
mkdir -p $iaskpagedir


for(( i=0; i<122; i++))
do
	urls=`$pydir/listurl.py "http://iask.sina.com.cn/browse/get_class.php?fatherid=216&status=K&page=${i}" "/b/.*"`
	echo "list url http://iask.sina.com.cn/browse/get_class.php?fatherid=216&status=K&page=${i} over"
	
	for url in ${urls}
	do
		file=`$pydir/quote.py http://iask.sina.com.cn${url}|tr '\n' ' '`
		echo tearing the page $url into file $file
		$pydir/tear.py `$pydir/unquote.py ${file}|tr '\n' ' '` $iaskpagedir/${file}&
		sleep 1
	done

done